package com.stormrage.entity.student;

import java.io.Serializable;
import java.util.Date;

import com.stormragetech.core.exception.StormrageTechException;
import com.stormragetech.core.util.NumberUtil;
import com.stormragetech.core.util.SecureUtil;

/**
 * @Title: StuAcct.java
 * @Package com.stormrage.entity.student
 * @Description: 学员 Entity 类
 * @author www.stormragetech.com
 * @date 2016年4月10日
 * @version V1.0
 */
public class StuAcct implements Serializable {

	// ------------------------------- Fields -------------------------------

	private static final long serialVersionUID = 3778137459280516343L;

	private Integer id; // 编号

	private String acct; // 用户名

	private String pass; // 密码

	private String salt; // 盐

	private String avatar;

	private Integer type;

	private String stuNo;

	private String nickName; // 真实姓名

	private Date regDate;

	private Integer locked;

	// ------------------------------- Fields -------------------------------

	public StuAcct() {

	}

	// ------------------------------- Fields -------------------------------

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getAcct() {
		return acct;
	}

	public void setAcct(String acct) {
		this.acct = acct;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}

	public String getSalt() {
		return salt;
	}

	public void setSalt(String salt) {
		this.salt = salt;
	}

	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
	}

	public String getStuNo() {
		return stuNo;
	}

	public void setStuNo(String stuNo) {
		this.stuNo = stuNo;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public Date getRegDate() {
		return regDate;
	}

	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}

	public Integer getLocked() {
		return locked;
	}

	public void setLocked(Integer locked) {
		this.locked = locked;
	}

	// ------------------------------- Fields -------------------------------

	public String getSign() {
		return acct + salt;
	}

	public static StuAcct instance() {
		StuAcct entity = new StuAcct();
		entity.setAcct("acct");
		entity.setPass("123456");
		entity.setSalt(SecureUtil.initUUID());
		entity.setAvatar("avatar.jpg");
		entity.setType(1);
		entity.setRegDate(new Date());
		entity.setLocked(0);
		return entity;
	}

	public static StuAcct instance(StuAcct arg0, Integer arg1) throws StormrageTechException {
		arg0.setId(arg1);
		arg0.setAcct("stu" + initAcct(arg1));
		arg0.setPass(SecureUtil.initPass("123456", arg0.getSign()));
		arg0.setStuNo(arg0.getAcct());
		return arg0;
	}

	@Override
	public String toString() {
		return this.getClass() + " : id - " + id + " acct - " + acct + " pass - " + pass + " salt - " + salt
				+ " avatar - " + avatar + " type - " + type + " stuNo - " + stuNo + " nickName - " + nickName
				+ " regDate - " + regDate + " locked - " + locked;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		StuAcct acct = (StuAcct) o;

		if (id != null ? !id.equals(acct.id) : acct.id != null)
			return false;

		return true;
	}

	@Override
	public int hashCode() {
		return id != null ? id.hashCode() : 0;
	}

	private static String initAcct(Integer arg0) throws StormrageTechException {
		if (null == arg0)
			return null;
		return NumberUtil.initZero(arg0, 8);
	}

}
